﻿
using System.Web;

namespace Mitmar.Web.Mvc.DNN
{

    #region "IResponse"

    public interface IResponse
    {
        void Clear();
        void Write(string data);
        int StatusCode { get; set; }
        string StatusDescription { get; set; }
        void End();
        int Expires { get; set; }
        void Cache_SetNoServerCaching();
        void Cache_SetNoStore();
        void AppendHeader(string header, string value);
        string ContentType { get; set; }
        void Redirect(string url);
        void Redirect(string url, bool endResponse);
        bool EndCalled { get; set; }
    }

    #endregion



    #region "ASPResponse"

    class ASPResponse : IResponse
    {


        private HttpResponse _response = HttpContext.Current.Response;
        public void AppendHeader(string header, string value)
        {
            _response.AppendHeader(header, value);
        }

        public void Cache_SetNoServerCaching()
        {
            _response.Cache.SetNoServerCaching();
        }

        public void Cache_SetNoStore()
        {
            _response.Cache.SetNoStore();
        }

        public void Clear()
        {
            _response.Clear();
        }

        public string ContentType
        {
            get { return _response.ContentType; }
            set { _response.ContentType = value; }
        }

        public void End()
        {
            _endCalled = true;
            _response.End();
        }

        public int Expires
        {
            get { return _response.Expires; }
            set { _response.Expires = value; }
        }

        public int StatusCode
        {
            get { return _response.StatusCode; }
            set { _response.StatusCode = value; }
        }

        public string StatusDescription
        {
            get { return _response.StatusDescription; }
            set { _response.StatusDescription = value; }
        }

        public void Write(string data)
        {
            _response.Write(data);
        }

        private bool _endCalled;
        public bool EndCalled
        {
            get { return _endCalled; }
            set { _endCalled = value; }
        }

        public void Redirect(string url)
        {
            Redirect(url, true);
        }

        public void Redirect(string url, bool endResponse)
        {
            _response.Redirect(url, endResponse);
        }
    }

    #endregion

}
